/**
 * @author Nicolas Latorre (nicolas.latorre@usi.ch)
 * @author Nicolas Zimerman (zimerman@usi.ch)
 */
package ch.usi.inf.pf2.file.interaction;

import java.util.ArrayList;

public final class Lexer {

    private String text;
    private Token token;
    private ComponentRecognizer recognizer;
    private ArrayList<Token> tokens;
    private int position;
    
    public Lexer(String textToMatch) {
    	text = textToMatch;
    	recognizer = new ComponentRecognizer(text);
    	tokens = new ArrayList<Token>();
    	position = 0;
    }
    
    public void setText(String text) {
    	this.text = text;
    }
    
    public void fetchNextToken() {
    	boolean test = recognizer.find(position);
   		position = position + recognizer.getMatcherLength();
   		System.out.println(position);
   		if(test) {
   			token = recognizer.getToken();
    		tokens.add(token);
    	}
    }
    
//    public void fetchAllTokens() {
//   		System.out.println(position);
//   		while(recognizer.find(position) != false) {
//   			position = position + recognizer.getMatcherLength();
//   			token = recognizer.getToken();
//    		tokens.add(token);
//    	}
//    }
    
    public Token getCurrentToken() {
    	return token;
    }
    
    public ArrayList<Token> getTokens() {
    	return tokens;
    }
    
    public ComponentRecognizer getRecognizer() {
    	return recognizer;
    }
    
    public int getPosition() {
    	return position;
    }
    
}